<template>
	<view class="follow-icons" @click.stop="handleCollection">
		<uni-icons color="#ff6600" :type="isSave ? 'heart-filled':'heart'" :size="followSize"></uni-icons>
	</view>
</template>

<script>
	export default {
		name: "Follow",
		props: {
			articleId: String,
			followSize: {
				type: String,
				default: "20"
			}
		},
		data() {
			return {

			};
		},
		computed: {
			//判断是否收藏了该文章
			isSave() {
				try {
					return this.userInfo && this.userInfo.article_likes_ids.includes(this.articleId)
				} catch (e) {
					return false
				}

			}
		},

		methods: {
			async handleCollection() {

				//判断用户是否登录
				await this.checkedisLogin()
				const {
					msg,
					newUserInfo
				} = await this.$http.update_save_like({
					articleId: this.articleId,
					userId: this.userInfo._id
				});
				uni.showToast({
					title: msg,
					icon: "none"
				});
				this.updetaUserInfo({
					...this.userInfo,
					...newUserInfo
				})
				this.isType = !this.isType
				uni.$emit('updateFolloArticleList')
			},

		}

	}
</script>

<style scoped lang="scss">

</style>
